﻿/*****************************************************************************
 
 Use of Ext is under the Ext JS license, for more information, 
 please visit http://extjs.com/products/license.php page. 
  
 You should confirm that you have read, understood and accept ethical criteria listed. 
 If not, see <http://www.mvcnext.com/license/>.
  
 Version: 1.0.0.0
 Website: http://www.mvcnext.com/
 
 Copyright (c) Yoganand R. All rights reserved.
 For continued development and updates, visit http://yogsbreath.net
 
 ******************************************************************************/
using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Web.UI;

namespace MVCnExt.Web.UI.Ext
{
    /// <summary>
    /// Single radio field. Can be used as a direct replacement for traditional Radio controls.
    /// </summary>
    [Description("Single radio field. Can be used as a direct replacement for traditional Radio controls.")]
    public class ExtDateField : TriggerField  
    {
        public override List<ScriptReference> GetScriptReferences()
        {
            return base.GetScriptReferences();
        }

        public override IList<ScriptDescriptor> GetScriptDescriptors()
        {
            IList<ScriptDescriptor> list = base.GetScriptDescriptors();

            ScriptControlDescriptorBase desc = (ScriptControlDescriptorBase)list[0];

            desc.Type = "Ext.form.DateField";

            String[] properties = new String[]{
                "altFormats", "disabledDatesText", "disabledDays", "disabledDaysText", "format", "maxText", "maxDate",
                "minText", "minDate", "cancelText", "monthYearText", "nextText", "okText", "prevText", "startDay",
                "todayText", "todayTip" 
            };

            Type component = typeof(ExtDateField);

            foreach (String property in properties)
            {
                PropertyInfo i = component.GetProperty(property);

                if (i == null)
                    throw new InvalidOperationException(String.Format("Property not found, 'ExtDateField.{0}'", property));

                Object value = i.GetValue(this, null);

                if (value == null)
                {
                    continue;
                }

                if (!(value is String) && !(value is DateTime))
                    desc.AddPropertyBase(property, value);
                else
                    desc.AddPropertyBase(property, String.Format("'{0}'", value));
            }                        

            return list;
        }

        #region Public Properties

        ///// <summary>
        ///// Gets or sets the current selected date of the DatePicker. Accepts and returns a DateTime object.
        ///// </summary>
        //[Description("Gets or sets the current selected date of the DatePicker. Accepts and returns a DateTime object.")]
        //public DateTime selectedDate { get; set; }

        /// <summary>
        /// Multiple date formats separated by \" | \" to try when parsing a user input value and it doesn't match the defined format ('MM/dd/yyyy|MM-dd-yy|MM-dd-yyyy|MM/dd|MM-dd|dd').
        /// </summary>
        [Description("Multiple date formats separated by \" | \" to try when parsing a user input value and it doesn't match the defined format ('MM/dd/yyyy|MM-dd-yy|MM-dd-yyyy|MM/dd|MM-dd|dd').")]
        public Boolean altFormats { get; set; }

        /// <summary>
        /// An array of \"dates\" to disable, as strings. These strings will be used to build a dynamic regular expression so they are very powerful.
        /// </summary>
        [Description("An array of \"dates\" to disable, as strings. These strings will be used to build a dynamic regular expression so they are very powerful.")]
        public String[] disabledDates { get; set; }

        /// <summary>
        /// The tooltip text to display when the date falls on a disabled date (defaults to 'Disabled').")]
        /// </summary>
        [Description("The tooltip text to display when the date falls on a disabled date (defaults to 'Disabled').")]
        public String disabledDatesText { get; set; }

        /// <summary>
        /// An array of days to disable, 0 based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
        /// </summary>
        [Description("An array of days to disable, 0 based. For example, [0, 6] disables Sunday and Saturday (defaults to null).")]
        public String disabledDays { get; set; }

        /// <summary>
        /// The tooltip to display when the date falls on a disabled day (defaults to 'Disabled').
        /// </summary>
        [Description("The tooltip to display when the date falls on a disabled day (defaults to 'Disabled').")]
        public String disabledDaysText { get; set; }

        /// <summary>
        /// The tooltip to display when the date falls on a disabled day (defaults to 'Disabled').
        /// </summary>
        [Description("The tooltip to display when the date falls on a disabled day (defaults to 'Disabled').")]
        public String format { get; set; }

        /// <summary>
        /// The error text to display when the date in the cell is after MaxValue (defaults to 'The date in this field must be before {MaxValue}').
        /// </summary>
        [Description("The error text to display when the date in the cell is after MaxValue (defaults to 'The date in this field must be before {MaxValue}').")]
        public String maxText { get; set; }

        /// <summary>
        /// The maximum allowed date.
        /// </summary>
        [Description("The maximum allowed date.")]
        public DateTime maxDate { get; set; }

        /// <summary>
        /// The error text to display when the date in the cell is before MinValue (defaults to 'The date in this field must be after {MinValue}').
        /// </summary>
        [Description("The error text to display when the date in the cell is before MinValue (defaults to 'The date in this field must be after {MinValue}').")]
        public String minText { get; set; }

        /// <summary>
        /// The minimum allowed date.
        /// </summary>
        [Description("The minimum allowed date.")]
        public DateTime minDate { get; set; }

        /// <summary>
        /// The text to display on the cancel button.
        /// </summary>
        [Description("The text to display on the cancel button.")]
        public String cancelText { get; set; }

        /// <summary>
        /// An array of textual day names which can be overriden for localization support (defaults to Date.dayNames).
        /// </summary>
        [Description("An array of textual day names which can be overriden for localization support (defaults to Date.dayNames).")]
        public String[] dayNames { get; set; }

        /// <summary>
        /// An array of textual month names which can be overriden for localization support (defaults to Date.monthNames).
        /// </summary>
        [Description("An array of textual month names which can be overriden for localization support (defaults to Date.monthNames).")]
        public String[] monthNames { get; set; }

        /// <summary>
        /// The header month selector tooltip (defaults to 'Choose a month (Control+Up/Down to move years)').
        /// </summary>
        [Description("The header month selector tooltip (defaults to 'Choose a month (Control+Up/Down to move years)').")]
        public String monthYearText { get; set; }

        /// <summary>
        /// The next month navigation button tooltip (defaults to 'Next Month (Control+Right)').
        /// </summary>
        [DefaultValue("Next Month (Control+Right)")]
        [Description("The next month navigation button tooltip (defaults to 'Next Month (Control+Right)').")]
        public String nextText { get; set; }

        /// <summary>
        /// The text to display on the ok button.
        /// </summary>
        [Description("The text to display on the ok button.")]
        public String okText { get; set; }

        /// <summary>
        /// The previous month navigation button tooltip (defaults to 'Previous Month (Control+Left)').
        /// </summary>
        [DefaultValue("Previous Month (Control+Left)")]
        [Description("The previous month navigation button tooltip (defaults to 'Previous Month (Control+Left)').")]
        public String prevText { get; set; }

        /// <summary>
        /// Day index at which the week should begin, 0-based (defaults to 0, which is Sunday).
        /// </summary>
        [DefaultValue(0)]
        [Description("Day index at which the week should begin, 0-based (defaults to 0, which is Sunday).")]
        public String startDay { get; set; }

        /// <summary>
        /// The text to display on the button that selects the current date (defaults to 'Today').
        /// </summary>
        [DefaultValue("Today")]
        [Description("The text to display on the button that selects the current date (defaults to 'Today').")]
        public String todayText { get; set; }

        /// <summary>
        /// The tooltip to display for the button that selects the current date (defaults to '{current date} (Spacebar)').
        /// </summary>       
        [DefaultValue("{current date} (Spacebar)")]
        [Description("The tooltip to display for the button that selects the current date (defaults to '{current date} (Spacebar)').")]
        public String todayTip { get; set; }        
       
        #endregion
    }
}
